package com.itheima.dubbo.service;

import com.itheima.dubbo.User;
import com.itheima.dubbo.UserFace;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.config.annotation.Method;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.beans.factory.annotation.Value;

@DubboService
//@DubboService(timeout = 1000)
//@DubboService(methods = {
//        @Method(name = "getById" ,timeout = 1800)
//})
//@DubboService(retries = 0)
//@DubboService(methods = {
//        @Method(name = "add" ,retries = 0)
//})
//@DubboService(version = "1.0.0")
public class UserFaceImpl implements UserFace {

    @Override
    public String hello(String username) {
        return "hello dubbo" + username;
    }

    @Value("${server.port}")
    private Integer port;

    @Override
    public User getById(User user) {

        User userResult = new User(user.getId(),"程序员",8);

        System.out.println("is running" + port);

        String itname = RpcContext.getContext().getAttachment("itname");
        System.out.println(itname);

//        try{
//            Thread.sleep(2000);
//        }catch (InterruptedException e){
//            e.printStackTrace();
//        }

        return userResult;
    }
}
